﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.XtraSpreadsheet.Model;
using TheHeGeo.Util;

namespace TheHeGeo.Master
{
    public partial class UcNsd : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session[SessionConst.SES_USER] == null)
                {
                    if (Session[SessionConst.SES_MENU_LANGUE] == null ||
                        Session[SessionConst.SES_MENU_LANGUE].ToString() == "0")
                    {
                        lblLeft.Text = "Đăng nhập";
                        lblLeft.NavigateUrl = "../Home/Login.aspx";
                        lblRight.Text = "Đăng ký";
                        
                    }
                    else
                    {
                        lblLeft.Text = "Login";
                        lblLeft.NavigateUrl = "../Home/Login.aspx";
                        lblRight.Text = "Register";
                        lblRight.NavigateUrl = "../Home/NewAccount.aspx";
                    }
                    
                }
                else
                {
                    var nsd = ((SessionUser)Session[SessionConst.SES_USER]).NguoiSuDung;
                    lblLeft.Text = nsd.UserName;
                    if (Session[SessionConst.SES_MENU_LANGUE] == null || Session[SessionConst.SES_MENU_LANGUE].ToString() == "0")
                    {
                        lblRight.Text = "Đăng xuất";
                         lblRight.NavigateUrl = "../Home/Logout.aspx";
                    }
                    else
                    {
                        lblRight.Text = "Logout";
                        lblRight.NavigateUrl = "../Home/Logout.aspx";
                    }
                }
            }
        }

        protected void imgVietNamese_Click(object sender, ImageClickEventArgs e)
        {
            Session[SessionConst.SES_MENU_LANGUE] = "0";
            String url = HttpContext.Current.Request.Url.PathAndQuery;
            var lUrl = url.Split('.');
            if (lUrl.Length < 2)
                return;
            if (!lUrl[0].EndsWith("English"))
                return;
            var Url = lUrl[0].Split('_');

            url = "";
            foreach (var s in Url)
            {
                if (!s.Contains("English"))
                    url += s;
            }
            Response.Redirect("~/" + url +"."+ lUrl[1]);
        }

        protected void imgEnglish_Click(object sender, ImageClickEventArgs e)
        {
            Session[SessionConst.SES_MENU_LANGUE] = "1";
            String url = HttpContext.Current.Request.Url.PathAndQuery;
            var Url = url.Split('.');
            if (Url.Length < 2)
                return;
            if (Url[0].EndsWith("English"))
                return;
            var lUrl = url.Split('.');
            url = lUrl[0] + "_English." + Url[1];
            Response.Redirect("~" + url);
        }
    }
}